#!/usr/bin/bash

# tmuxdumpclean v0.1.0
# clean tmux session's windows's path in $HOME/.tmux/tmuxsession_\$SESSION.windows
# Copyright by calvin 2021

function usage()
{
	echo "USAGE : tmuxdumpclean [ match ]"
	exit 1
}

if [ $# -eq 1 ] && [ x"$1" = x"?" ] ; then
	usage
	exit 1
elif [ $# -gt 1 ] ; then
	usage
	exit 1
fi

MATCH=$1

if [ ! -d $HOME/.tmux ] ; then
	mkdir -p $HOME/.tmux
fi

ls $HOME/.tmux/tmuxsession_*$MATCH*.windows >/dev/null
R=$?
if [ $R -ne 0 ] ; then
	exit $R
fi

ls $HOME/.tmux/tmuxsession_*$MATCH*.windows | while read CLEANFILE ; do
	echo "$CLEANFILE"
done
while [ 1 ] ; do
	printf "Confirm rm above all files ?(y/n) "
	read YES_OR_NO
	if [ x"${YES_OR_NO}" = x"n" ] ; then
		exit 0
	elif [ x"${YES_OR_NO}" = x"y" ] ; then
		break
	fi
done

ls $HOME/.tmux/tmuxsession_*$MATCH*.windows | while read CLEANFILE ; do
	echo "rm $CLEANFILE"
	rm $CLEANFILE
done

